<template>
  <span>chartverivew</span>
  <el-button type="primary" @click="function () { $router.push('/inventoryview') }">
    routertoinvent
  </el-button>

  <el-button type="primary" @click="changemainchartdata()">
    changemainchartdata
  </el-button>

  <!-- <v-chart :option="chartOption" style="width: 100%; height: 400px;" /> -->

  <div id="mainchart" style="width: 100%; height: 400px"></div>
</template>

<script>
import router from '@/router';
import * as echarts from "echarts";
// 基于准备好的dom，初始化echarts实例
var myChart

export default {
  name: "ChartOverview",
  data() {
    return {
      chartoption: {
        title: {
          text: 'ECharts 入门示例'
        },
        tooltip: {},
        legend: {
          data: ['销量']
        },
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
          {
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 40]
          }
        ]
      }
    }
  },
  components: {

  },
  mounted() {
    myChart = echarts.init(document.getElementById('mainchart'));
    this.initchart();
  },
  methods: {
    routerpushsys() {
      router.push('/inventoryview');
    },
    initchart() {

      // 指定图表的配置项和数据
      var option = this.chartoption;
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    },
    changemainchartdata() {
    
      // console.log(typeof this.chartoption.series[0].data);
      // console.log(Array.isArray(this.chartoption.series[0].data)); // 输出: true
      // console.log(this.chartoption.series[0].data.length);
      for (let i = 0; i < this.chartoption.series[0].data.length; i++) {
        this.chartoption.series[0].data[i] += 10;
      }
      this.initchart();
    },
  }
}
</script>

<style scoped></style>
